package com.no.seckill.controller;

import com.no.seckill.common.ErrorCode;
import com.no.seckill.common.ResponseModel;
import com.no.seckill.entity.Provider;
import com.no.seckill.service.Impl.ProviderServiceImpl;
import com.no.seckill.service.ProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhang kun
 * @Classname ProviderController
 * @Description TODO
 * @Date 2021/9/1 22:39
 */
@Controller
@RequestMapping("/provider")
public class ProviderController implements ErrorCode {
    @Autowired
    private ProviderServiceImpl providerService;

    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @RequestMapping(path = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ResponseModel add(@RequestBody Provider provider){
        providerService.insert(provider);
        return new ResponseModel(provider);
    }
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    @ResponseBody
    public ResponseModel update(Provider provider){
        providerService.update(provider);
        return new ResponseModel(provider);
    }

    @RequestMapping(path = "/select")
    @ResponseBody
    public ResponseModel select(Provider provider){
        List<Provider> list = providerService.selectAll();
        return new ResponseModel(list);
    }

    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public ResponseModel delete(Provider provider){
        String name = provider.getPname();
        String code = provider.getPcode();
        providerService.delete(name,code);
        return new ResponseModel(provider);
    }

}
